package com.zqh.irmadscore.controller;


import com.zqh.irmadscore.model.entity.FailureItem;
import com.zqh.irmadscore.service.FailureItemService;
import com.zqh.irmadscore.service.FileDealService;
import com.zqh.irmadscore.utils.resultUtils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/alert")
@RequiredArgsConstructor
@Tag(name = "警报管理")
public class AlertController {

    private final FileDealService fileDealService;
    private final FailureItemService failureItemService;

    // 根据查询所有历史记录
    @GetMapping("/history")
    @Operation(summary = "获取所有故障历史记录")
    public Result<List<FailureItem>> getHistory() {

        var list = failureItemService.list();
        return Result.ok(list);
    }

    @PostMapping()
    @Operation(summary = "读取上传的excel表格记录警告的历史")
    public Result<String> importAlertHistory(@RequestParam("file") MultipartFile file) throws Exception {

        boolean b = fileDealService.importAlertHistory(file);

        return Result.ok("警告历史保存成功");

    }



}
